package com.seeyon.apps.kk.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.seeyon.apps.kk.manager.AssetCardSyncManagerImpl;
import com.seeyon.apps.kk.manager.OrgSyncEmailManagerImpl;
import com.seeyon.apps.kk.manager.OrgSyncManagerImpl;
import com.seeyon.apps.kk.manager.TemplateTongManagerImpl;
import com.seeyon.ctp.common.AppContext;

/**
 * 手动调用测试controller
 * @author yonyou
 *
 */
public class DataSyncController extends KkBaseController {

	private AssetCardSyncManagerImpl managerImpl = (AssetCardSyncManagerImpl) AppContext
			.getBean("assetCardSyncManagerImpl");
	private OrgSyncManagerImpl impl = (OrgSyncManagerImpl) AppContext.getBean("kkOrgSyncManagerImpl");

	private TemplateTongManagerImpl tongManagerImpl = (TemplateTongManagerImpl) AppContext
			.getBean("templateTongManagerImpl");

	private OrgSyncEmailManagerImpl emailManagerImpl = (OrgSyncEmailManagerImpl) AppContext
			.getBean("orgSyncEmailManagerImpl");
	
	public ModelAndView sync(HttpServletRequest request, HttpServletResponse response) {
		/*
		 * managerImpl.addSupplier(); managerImpl.addWorkType();
		 */
		Map<String, String> map = impl.orgMember();
		if (map.get("code").equals("1000"))
			return this.ajaxDoneSuccess("添加成功", JSON.toJSONString(map));
		else
			return this.ajaxDoneError(JSON.toJSONString(map));
	}

	public ModelAndView OrgSync(HttpServletRequest request, HttpServletResponse response) {
		Map<String, String> map = impl.orgSync();
		if (map.get("code").equals("1000"))
			return this.ajaxDoneSuccess("添加成功", JSON.toJSONString(map));
		else
			return this.ajaxDoneError(JSON.toJSONString(map));
	}

	public ModelAndView kaoqin(HttpServletRequest request, HttpServletResponse response) {
		tongManagerImpl.sendTONCVacationInsert();
		return this.ajaxDoneSuccess("添加成功", JSON.toJSONString("数据测试！"));
	}

	public ModelAndView orgTOMeeting(HttpServletRequest request, HttpServletResponse response) {
		Map<String, String> map = impl.orgTOMeeting();
		if (map.get("code").equals("1000"))
			return this.ajaxDoneSuccess("添加成功", JSON.toJSONString(map));
		else
			return this.ajaxDoneError(JSON.toJSONString(map));
	}

	public ModelAndView org(HttpServletRequest request, HttpServletResponse response) {
		Map<String, String> map = impl.org();
		if (map.get("code").equals("1000"))
			return this.ajaxDoneSuccess("添加成功", JSON.toJSONString(map));
		else
			return this.ajaxDoneError(JSON.toJSONString(map));
	}
	
	public ModelAndView celiang(HttpServletRequest request, HttpServletResponse response) {
		managerImpl.dataInit();
		managerImpl.insertData();
		managerImpl.updData();
		return this.ajaxDoneSuccess("添加成功", JSON.toJSONString("测量设备数据同步成功"));
	}
	
	
	public ModelAndView work(HttpServletRequest request, HttpServletResponse response) {
		managerImpl.addSupplier();
		managerImpl.addWorkType();
		return this.ajaxDoneSuccess("添加成功", JSON.toJSONString("供应商数据同步"));
	}
	
	/**
	 * 邮箱组织架构初始化
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView emailOrg(HttpServletRequest request, HttpServletResponse response) {
		Map<String, String> map = emailManagerImpl.init();
		if (map.get("code").equals("1000"))
			return this.ajaxDoneSuccess("添加成功", JSON.toJSONString(map));
		else
			return this.ajaxDoneError(JSON.toJSONString(map));
	}
	/**
	 * 项目档案底表同步至NC
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView pro(HttpServletRequest request, HttpServletResponse response) {
		impl.syncTONCPro();
		return this.ajaxDoneSuccess("添加成功", JSON.toJSONString(""));
		
	}
	/**
	 * 同步资金项目计划
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView syncFundPlan(HttpServletRequest request, HttpServletResponse response) {
		impl.syncFundPlan();
		return this.ajaxDoneSuccess("添加成功", JSON.toJSONString(""));
		
	}
}
